﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Windows.Forms; // TODO: törölni

namespace SedCup.Code.Model
{
    public class MainDAO
    {
        private MainController mainController;

        private static readonly String connectionString = @"Data Source=..\..\..\..\db\sedcup.s3db;";

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="mainController"></param>
        public MainDAO(MainController mainController)
        {
            this.mainController = mainController;

            try
            {
                Test();  // TODO: törölni
            }
            catch (SQLiteException e)
            {
                MessageBox.Show(e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        /// Adatbázis tesztelő függvény
        /// </summary>
        /// <exception cref="SQLiteException"></exception>
        public void Test() // TODO: törölni
        {
            using (SQLiteConnection conn = new SQLiteConnection(connectionString))
            {
                // további minta a Dropbox\verseny\erőforrások\mintakódok\adatbázis mappában

                SQLiteCommand command = conn.CreateCommand();

                command.CommandText = "select * from test";

                conn.Open();

                SQLiteDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    MessageBox.Show("Key: " + reader["key"].ToString() + " , value: " + reader["value"].ToString());
                }
            }
        }
    }
}
